//
//  MBSongDetailForIpadController.m
//  MiBaoTu
//
//  Created by mac004 on 2016/11/9.
//  Copyright © 2016年 com.caesartech15. All rights reserved.
//

#import "MBSongDetailForIpadController.h"
#import "DXSemiViewControllerCategory.h"
#import "MBButtonView.h"
#import "MBLoginController.h"
#import "AppDelegate.h"

#import <MediaPlayer/MediaPlayer.h>
#define TABLE_ROW_HEIGHT (35)\

@interface MBSongDetailForIpadController ()<MBButtonViewDelegate>
{
    NSTimer                 *_showTimer;
    BOOL                    isFromBackGround;  //是否从后台切入
    UIView                  *noLrcView;     //无歌词显示view
    NSMutableArray                 *collectionMusicArr; //收藏歌曲
    PLayerModelType         playModelType;      //播放模式
    NSMutableArray          *fileIDArr;
    CLShareManager                  *shareView;          //分享
    int                         nextPlay;
    UIImageView             *_BGImgView;//背景图
    UIImageView             *_bigSongImg;//歌曲大图
    UIImageView             *_smallSongImg;//歌曲小图
    MBButtonView               *buttonView;
    UIImageView               *_anchorImg;//主播头像
    UIView                  *blurryView;//视图模糊层
    NSMutableDictionary            *statusDic;//收藏状态
    UIButton                *nextBt;
    UIButton                *lastBtn;
    AVAudioSession          *_audioSession;
}

@property (strong, nonatomic)  MBButtonView *bottomView;
@property (weak, nonatomic)  UISlider *sliderBtn;
@end

@implementation MBSongDetailForIpadController
@synthesize  progressSlider, playBtn, circleBtn, currentTimeLabel, totalTimeLabel, lrcTableView, musicArray,singer,songName;
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    songName.text = [musicArray[musicArrayNumber] name];
    singer.text = [musicArray[musicArrayNumber] Singer];
    
    if ([UserManager standerDefult].mainPlayer && [UserManager standerDefult].isBackPlay && [UserManager standerDefult].audioPlayerType == AudioPLayerType_YinPin) {
        if (!_showTimer) {
            //设置监控 每秒刷新一次时间
            _showTimer =[NSTimer scheduledTimerWithTimeInterval:0.1f
                                                         target:self
                                                       selector:@selector(showTime)
                                                       userInfo:nil
                                                        repeats:YES];
        }
    }

}

- (void)viewWillDisappear:(BOOL)animated
{    [super viewWillDisappear:animated];
    
    //离开判断播放器是否正在播放
    if (_showTimer && [_showTimer isValid]) {
        [[UserManager standerDefult] setMainPlayer:audioPlayer];
        [[UserManager standerDefult]setIsBackPlay:playBtn.selected];
        
        [_showTimer invalidate];
        _showTimer = nil;
    } else {
        [[UserManager standerDefult] setMainPlayer:audioPlayer];
        [[UserManager standerDefult]setIsBackPlay:NO];
    }
    
    //表的显示区域最多显示的歌词行数
    int count = lrcTableView.height / TABLE_ROW_HEIGHT;
    count = count / 2;
    if (lrcLineNumber > count) {
        //显示在这行时，开始往上移动一个单元格高度
        [[UserManager standerDefult]setMainPoint:CGPointMake(0, TABLE_ROW_HEIGHT*(lrcLineNumber-count))];
    } else {
        [[UserManager standerDefult]setMainPoint:CGPointMake(0, 0)];
    }
    
    [[UserManager standerDefult]setSelectMusicIndex:musicArrayNumber];
    [[UserManager standerDefult]setMusicArr:musicArray];
    [[UserManager standerDefult]setIsPlaying:playBtn.selected];
    [[UserManager standerDefult]setIsOnlinePlayer:_isFromOnLine];
    
    [[NSUserDefaults standardUserDefaults]setObject:(_isFromOnLine?@1:@0) forKey:@"isOnlineForMusic"];
    [[NSUserDefaults standardUserDefaults]synchronize];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemFailedToPlayToEndTimeNotification object:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    isPlay = YES;            //是否处于播放状态
    isCircle = YES;          //判断是否允许循环播放
    lrcLineNumber = 0;
    musicArrayNumber = 0;    //歌曲列表中第几条
    timeArray = [[NSMutableArray alloc] initWithCapacity:10];               //时间
    LRCDictionary = [[NSMutableDictionary alloc] initWithCapacity:10];      //歌词
    collectionMusicArr = [[NSMutableArray alloc]init];                             //收藏
    
    fileIDArr = [[NSMutableArray alloc]init];  
    nextPlay = 1;
    
    //UI
    [self setupNavBar];
 
    
    //初始化要加载的曲目
    [self initDate];
    //初始化歌词词典
    [self initLRC];
    
    
    [self onCreateUI];
 
    
    self.view.backgroundColor = [UIColor whiteColor];
    shareView = [[CLShareManager alloc] init];
}



#pragma mark - UI
- (void)setupNavBar {
    
    [self setTitleView:[musicArray[musicArrayNumber] name]];
    if (_isFromOnLine) {
        songName.hidden = NO;
        singer.hidden = NO;
    } else {
        songName.hidden = YES;
        singer.hidden = YES;
    }
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"fanhui"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]style:UIBarButtonItemStylePlain target:self action:@selector(navigationBackButton)];
    //背景
    _BGImgView=[[UIImageView alloc]initWithFrame:self.view.bounds];
    _BGImgView.image=[UIImage imageNamed:@"bg2-2048-2"];
    [self.view addSubview:_BGImgView];
    
    //模糊层
    blurryView=[[UIView alloc]initWithFrame:self.view.bounds];
    blurryView.backgroundColor=[UIColorFromHex(0x000000) colorWithAlphaComponent:0.65];
    [self.view addSubview:blurryView];
    
    [self.view insertSubview:blurryView aboveSubview:_BGImgView];
    //歌曲大图
    _bigSongImg=[[UIImageView alloc]initWithFrame:CGRectMake(150*PERCEN, 250*PERCEN, SCREEN_WIDTH/2048*800, SCREEN_WIDTH/2048*800)];
    _bigSongImg.image=[UIImage imageNamed:@"moren_diantai"];
    [blurryView addSubview:_bigSongImg];
    
    //上一首
    UIImage *lastImg = [UIImage imageNamed:@"shangyiqu"];
    lastBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    lastBtn.frame = CGRectMake(80*PERCEN, _bigSongImg.bottom+326*PERCEN, 80*PERCEN, 80*PERCEN);
    lastBtn.backgroundColor = [UIColor clearColor];
    [lastBtn setImage:lastImg forState:UIControlStateNormal];
    [lastBtn setImage:lastImg forState:UIControlStateHighlighted];
    [lastBtn addTarget:self action:@selector(aboveMusic:) forControlEvents:UIControlEventTouchUpInside];
    [blurryView addSubview:lastBtn];
    
    //播放、暂停
    UIImage *playImg = [UIImage imageNamed:@"bofang_xbtj"];
    UIImage *playingImg = [UIImage imageNamed:@"zanting_xbtj"];
    playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    playBtn.backgroundColor = [UIColor clearColor];
    playBtn.frame = CGRectMake(lastBtn.right+50*PERCEN, _bigSongImg.bottom+316*PERCEN, 100*PERCEN, 100*PERCEN);
    [playBtn setBackgroundImage:playImg forState:UIControlStateNormal];
    [playBtn setBackgroundImage:playingImg forState:UIControlStateSelected];
    [playBtn addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];
    [blurryView addSubview:playBtn];
    
    
    //下一个
    UIImage *nextImg = [UIImage imageNamed:@"xiayiqu"];
    nextBt = [UIButton buttonWithType:UIButtonTypeCustom];
    nextBt.backgroundColor = [UIColor clearColor];
    nextBt.frame = CGRectMake(playBtn.right+50*PERCEN, _bigSongImg.bottom+326*PERCEN, 80*PERCEN, 80*PERCEN);
    [nextBt setImage:nextImg forState:UIControlStateNormal];
    [nextBt setImage:nextImg forState:UIControlStateHighlighted];
    [nextBt addTarget:self action:@selector(nextMusic:) forControlEvents:UIControlEventTouchUpInside];
    [blurryView addSubview:nextBt];
    
    
    //小图
    _smallSongImg=[[UIImageView alloc]initWithFrame:CGRectMake(nextBt.right+80*PERCEN, _bigSongImg.bottom+304*PERCEN, 120*PERCEN, 120*PERCEN)];
    _smallSongImg.image=[UIImage imageNamed:@"moren2_diantai"];
    [blurryView addSubview:_smallSongImg];
    
    songName=[[UILabel alloc]initWithFrame:CGRectMake(_smallSongImg.right+30*PERCEN, nextBt.top, 320*PERCEN, 30*PERCEN)];
    songName.font=[UIFont systemFontOfSize:30*PERCEN];
    songName.textColor=UIColorFromHex(0xffffff);
    songName.text=@"捉泥鳅";
    [blurryView addSubview:songName];
    
    //当前播放时间
    currentTimeLabel=[[UILabel alloc]initWithFrame:CGRectMake(_smallSongImg.right+600*PERCEN, songName.top+2*PERCEN, 100*PERCEN, 26*PERCEN)];
    currentTimeLabel.font=[UIFont systemFontOfSize:26*PERCEN];
    currentTimeLabel.textColor=UIColorFromHex(0xffffff);
    currentTimeLabel.text=@"00:00 ";
    [blurryView addSubview:currentTimeLabel];
    
    //分割线
    UILabel * label=[[UILabel alloc]initWithFrame:CGRectMake(currentTimeLabel.right-10*PERCEN, currentTimeLabel.top, 10*PERCEN, 26*PERCEN)];
    label.font=[UIFont systemFontOfSize:26*PERCEN];
    label.textColor=UIColorFromHex(0xffffff);
    label.text=@"/";
    [blurryView addSubview:label];
    //歌曲总时间
    totalTimeLabel=[[UILabel alloc]initWithFrame:CGRectMake(currentTimeLabel.right+20*PERCEN, songName.top+2*PERCEN, 80*PERCEN, 26*PERCEN)];
    totalTimeLabel.font=[UIFont systemFontOfSize:26*PERCEN];
    totalTimeLabel.textColor=UIColorFromHex(0xffffff);
    totalTimeLabel.text=@"00:00";
    [blurryView addSubview:totalTimeLabel];
    
    
    //进度条
    progressSlider = [[UISlider alloc]initWithFrame:CGRectMake(_smallSongImg.right+30*PERCEN, SCREEN_HEIGHT-100*PERCEN, 756*PERCEN, 4*PERCEN)];
    //    slide.backgroundColor = [UIColor colorWithRed:193/255. green:193/255. blue:193/255. alpha:1.];
    progressSlider.minimumValue = 0;
    progressSlider.maximumValue = 1;
    progressSlider.value = 0;
    progressSlider.minimumTrackTintColor = [UIColor colorWithRed:228/255. green:85/255. blue:150/255. alpha:1.];
    progressSlider.maximumTrackTintColor = [UIColor colorWithRed:193/255. green:193/255. blue:193/255. alpha:1.];
    [progressSlider setThumbImage:[UIImage imageNamed:@"lunbo1"] forState:UIControlStateNormal];
    [progressSlider setThumbImage:[UIImage imageNamed:@"lunbo1"] forState:UIControlStateHighlighted];
    //    [slide setTranslatesAutoresizingMaskIntoConstraints:NO];
    [blurryView addSubview:progressSlider];
    [progressSlider addTarget:self action:@selector(progressChange:) forControlEvents:UIControlEventValueChanged];
    
    //分享区域
    _bottomView =[[MBButtonView alloc]initWithFrame:CGRectMake(progressSlider.right+40*PERCEN,SCREEN_HEIGHT-150*PERCEN, 600*PERCEN, 60*PERCEN)];
    _bottomView.delegate=self;
    [blurryView addSubview:_bottomView];
    
    lrcTableView=[[UITableView alloc]initWithFrame:CGRectMake(_bigSongImg.right+138*PERCEN, _bigSongImg.top,SCREEN_WIDTH/2048*860 , SCREEN_WIDTH/2048*800) style:UITableViewStylePlain];
    lrcTableView.dataSource=self;
    lrcTableView.delegate=self;
    lrcTableView.separatorStyle= UITableViewCellSeparatorStyleNone;
    lrcTableView.backgroundColor=[UIColor clearColor];
    [blurryView addSubview:lrcTableView];


    
}

- (void)onCreateUI
{
    if (!_audioSession) {
        _audioSession = [AVAudioSession sharedInstance];
    }
    [_audioSession setActive:YES error:nil];
    [_audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];

    if ([UserManager standerDefult].mainPlayer) {
        if ([UserManager standerDefult].isPlaying) {
            _showTimer =[NSTimer scheduledTimerWithTimeInterval:0.1f
                                                         target:self
                                                       selector:@selector(showTime)
                                                       userInfo:nil
                                                        repeats:YES];
        }
        audioPlayer = [UserManager standerDefult].mainPlayer;
        isFromBackGround = YES;
        [[UserManager standerDefult] setIsBackPlay:NO];
        //歌词滚动
        [lrcTableView setContentOffset:[UserManager standerDefult].mainPoint animated:NO];
        
        //数据
        [musicArray removeAllObjects];
        [musicArray addObjectsFromArray:[UserManager standerDefult].musicArr];
        musicArrayNumber = [UserManager standerDefult].selectMusicIndex;
        
        playBtn.selected = [UserManager standerDefult].isPlaying;
        if (playBtn.selected) {
            [audioPlayer play];
        } else {
            [audioPlayer pause];
        }
        isPlay = !playBtn.selected;
    } else {
        NSURL *urlPath;
        if (currentMusic.isCacheData) {
            NSString *filePath = [MusicCachesDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp3",currentMusic.name]];
            urlPath = [NSURL fileURLWithPath:filePath];
        } else {
            urlPath = [NSURL URLWithString:currentMusic.urlPath];
        }
        
        AVPlayerItem *item =[AVPlayerItem playerItemWithURL:urlPath];
        audioPlayer = [[AVPlayer alloc]initWithPlayerItem:item];
        isFromBackGround = NO;
    }
    
    [self.sliderBtn setThumbImage:[UIImage imageNamed:@"lunbo1"] forState:UIControlStateNormal];
    self.bottomView.delegate = self;
    
    if ([UserManager standerDefult].musicPlayType == MusicPLayType_Online) {
        //在线
        _bigSongImg.image = [UIImage imageNamed:@"moren_diantai"];
        _smallSongImg.image = [UIImage imageNamed:@"moren2_diantai"];
        _BGImgView.image=[UIImage imageNamed:@"bg2-2048-2"];
    } else {
        _bigSongImg.image = [UIImage imageNamed:@"bofangqi_moren"];
         _smallSongImg.image = [UIImage imageNamed:@"bofangqi2_more"];
        _BGImgView.image=[UIImage imageNamed:@"bg1-2048-2"];
    }

    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieToEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieToFaile:) name:AVPlayerItemFailedToPlayToEndTimeNotification object:nil];

}

#pragma mark 通知方法
- (void)movieToEnd:(NSNotification*)noty
{
    if (audioPlayer && [UserManager standerDefult].isBackPlay == NO) {
        AVPlayerItem *currentItem = noty.object;
        if ([audioPlayer.currentItem isEqual:currentItem]) {
            [self autoPlay];
        }
    }
}

- (void)movieToFaile:(NSNotification *)noty
{
    if (audioPlayer && [UserManager standerDefult].isBackPlay == NO) {
        AVPlayerItem *currentItem = noty.object;
        if ([audioPlayer.currentItem isEqual:currentItem]) {
            [self autoPlay];
        }
    }
}

- (void)onUpdateUIForView:(UIDeviceOrientation)orientation
{
    if (noLrcView) {
        noLrcView.frame = lrcTableView.frame;
    }
}

-(void)navigationBackButton {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark 载入歌曲数组
- (void)initDate {
    
    //获取音频列表的歌曲数据
    NSMutableArray *musicArr = [UserManager standerDefult].musicArr;
    if (musicArr.count > 0) {
        musicArray = [[NSMutableArray alloc]initWithArray:musicArr];
    }
    //
    musicArrayNumber = [UserManager standerDefult].selectMusicIndex;
    
    //获取当前的歌曲信息
    if (musicArray.count > musicArrayNumber) {
        currentMusic = musicArray[musicArrayNumber];
    }
     NSLog(@"currentMusic==%@",currentMusic);
      [self setTitleView:[musicArray[musicArrayNumber] name]];
    if (![currentMusic.CoverPath isKindOfClass:[NSNull class]]) {
        //电台
        if ([UserManager standerDefult].musicPlayType == MusicPLayType_Online) {
            [_bigSongImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",MUSIC_PLAY_Url,currentMusic.CoverPath]] placeholderImage:[UIImage imageNamed:@"moren_diantai"]];
            [_smallSongImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",MUSIC_PLAY_Url,currentMusic.CoverPath]] placeholderImage:[UIImage imageNamed:@"moren2_diantai"]];
        }else{
        
        [_bigSongImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",MUSIC_PLAY_Url,currentMusic.CoverPath]] placeholderImage:[UIImage imageNamed:@"bofangqi_moren"]];
              [_smallSongImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",MUSIC_PLAY_Url,currentMusic.CoverPath]] placeholderImage:[UIImage imageNamed:@"bofangqi2_more"]];
        }
    }
    else {
        if ([UserManager standerDefult].musicPlayType == MusicPLayType_Online) {
            //在线
            _bigSongImg.image = [UIImage imageNamed:@"moren_diantai"];
            _smallSongImg.image = [UIImage imageNamed:@"moren2_diantai"];
          
        } else {
            _bigSongImg.image = [UIImage imageNamed:@"bofangqi_moren"];
            _smallSongImg.image = [UIImage imageNamed:@"bofangqi2_more"];
           
        }
      
        
    }
 
    
    //播放模式
    NSString *modelType = [[NSUserDefaults standardUserDefaults]objectForKey:@"player_model_type"];
    if (modelType.length == 0) {
        playModelType = PLayerModelType_Shunxu;
    } else {
        switch ([modelType intValue]) {
            case 1:
            {
                playModelType = PLayerModelType_Shunxu;
            }
                break;
            case 2:
            {
                playModelType = PLayerModelType_SuiJi;
            }
                break;
            case 3:
            {
                playModelType = PLayerModelType_DanQu;
            }
                break;
                
            default:
            {
                playModelType = PLayerModelType_Shunxu;
            }
                
                break;
        }
    }
    
    //歌曲列表保存
    [NSKeyedArchiver archiveRootObject:musicArray toFile:[MusicCachesDirectory stringByAppendingPathComponent:@"collectionMusic.data"]];
}

#pragma mark 得到歌词
- (void)initLRC {
    //收藏歌曲
    NSArray *musicCollecion = [UserManager standerDefult].collectionMusicArr;
    
      
    [collectionMusicArr removeAllObjects];
    
    if (musicCollecion.count > 0) {
        [collectionMusicArr addObjectsFromArray:musicCollecion];
        
    }
   
    [self onChangeCollectionType];
    
    //已下载歌曲记录
    
    NSArray *downedMusicArr = [UserManager standerDefult].downedMusicArr;
    [fileIDArr removeAllObjects];
    
    for (int i=0; i<downedMusicArr.count; i++) {
        NSDictionary *dic = [downedMusicArr objectAtIndex:i];
        NSString *fileID = [dic objectForKey:@"fileID"];
        [fileIDArr addObject:fileID];
    }
    
    //下载状态
    BOOL isDown = NO;
    for (NSString *fileID in fileIDArr) {
        if ([fileID isEqualToString:[NSString stringWithFormat:@"%@",currentMusic.ID]]) {
            isDown = YES;
        }
    }
    
    [_bottomView onUpdateDown:isDown withModel:currentMusic];
    
    //列入最近播放
    if (currentMusic.ID) {
        FMManageObject *manager = [FMManageObject standerDefault];
        NSArray *arrs = [manager SelectTableByMusicPlayForRecentWithContentID:[NSString stringWithFormat:@"%@",currentMusic.ID]];
        if (arrs.count == 0) {
            //来吧
            [manager insertTableMusicPlayForRecentWithId:@"1" withFileName:currentMusic.name withFileID:currentMusic.ID withUrl:currentMusic.urlPath withSize:currentMusic.Capacity withType:[NSString stringWithFormat:@"%@",currentMusic.musicType]];
        }
    }
    
    if (musicArray.count > musicArrayNumber) {
        [timeArray removeAllObjects];
        [LRCDictionary removeAllObjects];
        
        NSString *LRCPath = [MusicCachesDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.lrc",currentMusic.name]];
        NSFileManager *fileManger = [NSFileManager defaultManager];
        if (![fileManger fileExistsAtPath:LRCPath]) {
            [self addNoGeCi];
        } else {
            NSString *contentStr = [NSString stringWithContentsOfFile:LRCPath encoding:NSUTF8StringEncoding error:nil];
            if (contentStr.length == 0) {
                unsigned long encode = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
                NSData *responseData = [NSData dataWithContentsOfFile:LRCPath ];
                contentStr = [[NSString alloc] initWithData:responseData encoding:encode];
                
            }
            if (contentStr.length == 0) {
                [self addNoGeCi];
            } else {
              
                lrcTableView.hidden = NO;
                [blurryView insertSubview:lrcTableView aboveSubview:noLrcView];
                noLrcView.hidden = YES;
                noLrcView.alpha = 0;
                
                NSArray *array = [contentStr componentsSeparatedByString:@"\r\n"];
                
                if (array.count > 2) {
                    //正常的 每条歌词都换行
                    for (int i = 0; i < [array count]; i++) {
                        NSString *linStr = [array objectAtIndex:i];
                        NSArray *lineArray = [linStr componentsSeparatedByString:@"]"];
                        if ([lineArray[0] length] > 8) {
                            NSString *str1 = [linStr substringWithRange:NSMakeRange(3, 1)];
                            NSString *str2 = [linStr substringWithRange:NSMakeRange(6, 1)];
                            //[00:06.47]
                            if ([str1 isEqualToString:@":"] && [str2 isEqualToString:@"."]) {
                                NSString *lrcStr = [NSString stringWithFormat:@"%@",[lineArray objectAtIndex:1]];
                                if (lrcStr.length > 0) {
                                    NSString *timeStr = [[lineArray objectAtIndex:0] substringWithRange:NSMakeRange(1, 5)];//分割区间求歌词时间
                                    //把时间 和 歌词 加入词典
                                    [LRCDictionary setObject:lrcStr forKey:timeStr];
                                    [timeArray addObject:timeStr];//timeArray的count就是行数
                                }
                            }
                        }
                    }
                } else {
                    //没有换行，但是歌词都写在一起
                    NSString *lrcAllString = array[0];
                    NSArray *lineAllArray = [lrcAllString componentsSeparatedByString:@"["];
                    for (NSString *lrcLineStr in lineAllArray) {
                        
                        if ([lrcLineStr length] > 8) {
                            NSString *str1 = [lrcLineStr substringWithRange:NSMakeRange(2, 1)];
                            NSString *str2 = [lrcLineStr substringWithRange:NSMakeRange(5, 1)];
                            if ([str1 isEqualToString:@":"] && [str2 isEqualToString:@"."]) {
                                NSArray *lineArray = [lrcLineStr componentsSeparatedByString:@"]"];
                                NSString *lrcStr = [NSString stringWithFormat:@"%@",[lineArray objectAtIndex:1]];
                                if (lrcStr.length > 0) {
                                    NSString *timeStr = [[lineArray objectAtIndex:0] substringWithRange:NSMakeRange(0, 5)];//分割区间求歌词时间
                                    //把时间 和 歌词 加入词典
                                    [LRCDictionary setObject:lrcStr forKey:timeStr];
                                    [timeArray addObject:timeStr];//timeArray的count就是行数
                                }
                            }
                        }
                    }
                }
                [lrcTableView reloadData];
            }
            
        }
        
        if (LRCDictionary.allKeys.count == 0) {
            [self addNoGeCi];
        }
    } else {
        [self addNoGeCi];
    }
    
    //当前第几首歌以及类型播放器
    [[NSUserDefaults standardUserDefaults]setObject:[NSString stringWithFormat:@"%d",(int)musicArrayNumber] forKey:@"music_list_CurrentNum"];
    [[NSUserDefaults standardUserDefaults]setObject:[NSString stringWithFormat:@"%d",(int)0] forKey:@"music_Type_CurrentNum"];
    [[NSUserDefaults standardUserDefaults]synchronize];
    
    [audioPlayer play];
    
    [self onAddMedia];
 
}

//锁屏显示
- (void)onAddMedia
{
    Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");
    if (playingInfoCenter) {
        
        NSMutableDictionary *songInfo = [ [NSMutableDictionary alloc] init];
        MPMediaItemArtwork *albumArt = [ [MPMediaItemArtwork alloc] initWithImage:_bigSongImg.image];
        
    [ songInfo setObject:currentMusic.name forKey:MPMediaItemPropertyTitle ];
        NSString *singerStr = currentMusic.Singer;
        if ([singerStr isKindOfClass:[NSString class]]) {
            if (singerStr.length > 0) {
                [ songInfo setObject:singerStr forKey:MPMediaItemPropertyArtist ];
            }
        }
        //        [ songInfo setObject: @"Audio Album" forKey:MPMediaItemPropertyAlbumTitle ];
        [ songInfo setObject: albumArt forKey:MPMediaItemPropertyArtwork ];
        //设置歌曲时长
        NSLog(@"seee==%@",totalTimeLabel.text);
        NSArray *arr2 = [totalTimeLabel.text componentsSeparatedByString:@":"];
        double totalTime = 0;
        if (arr2.count == 2) {
            totalTime = [arr2[0] intValue]*60. + [arr2[1] intValue];
        } else {
            totalTime = [arr2[0] intValue];
        }
        [songInfo setObject:[NSNumber numberWithDouble:totalTime] forKey:MPMediaItemPropertyPlaybackDuration];
        //设置已经播放时长
        NSArray *arr1 = [currentTimeLabel.text componentsSeparatedByString:@":"];
        double currentTime = 0;
        if (arr1.count == 2) {
            currentTime = [arr1[0] intValue]*60. + [arr1[1] intValue];
        } else {
            currentTime = [arr1[0] intValue];
        }
        [songInfo setObject:[NSNumber numberWithDouble:currentTime] forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];
        
        [ [MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo ];
    }
}



- (void)addNoGeCi
{
    if (noLrcView) {
        NSLog(@"存在");
      
    }
    NSString *lrcString = currentMusic.LyricPath;
    if (![lrcString isKindOfClass:[NSNull class]]) {
        lrcString =[NSString stringWithFormat:@"%@%@",MUSIC_PLAY_Url,lrcString];
        [[DownLRCManager staredInstance]downloadWithUrl:lrcString withMusicName:currentMusic.name];
    }
    //无歌曲
    if (!noLrcView) {
        NSLog(@"没有歌词");
        noLrcView = [[UIView alloc]initWithFrame:lrcTableView.frame];
        noLrcView.backgroundColor = [UIColor clearColor];
        [blurryView addSubview:noLrcView];
        
        UIImage *img = [UIImage imageNamed:@"zanwugeci"];
        UIImageView *imgLrcView = [[UIImageView alloc]initWithFrame:CGRectMake((noLrcView.width-img.size.width)/2., ((noLrcView.height - img.size.height - 20)/2.), img.size.width, img.size.height)];
        imgLrcView.image = img;
        imgLrcView.backgroundColor = [UIColor clearColor];
        [noLrcView addSubview:imgLrcView];
        
        UILabel *noLrcLb = [[UILabel alloc]initWithFrame:CGRectMake(0, imgLrcView.bottom+20, noLrcView.width, 20)];
        noLrcLb.text =@"暂无歌词";
        noLrcLb.textAlignment = NSTextAlignmentCenter;
        noLrcLb.textColor = [UIColor whiteColor];
        noLrcLb.font = [UIFont systemFontOfSize:14.f];
        [noLrcView addSubview:noLrcLb];
    }
    
    lrcTableView.hidden = YES;
     noLrcView.hidden = NO;
     noLrcView.alpha = 1;
    [blurryView insertSubview:noLrcView aboveSubview:lrcTableView];
}

- (void)onChangeCollectionType
{
    //播放当前歌曲时，判断是否该歌曲收藏
    BOOL isPraise = NO;
    
    for (NSString *praiseType in collectionMusicArr) {
        
        
        if ([praiseType intValue] == [currentMusic.ID intValue]) {
            isPraise = YES;
        }
    }
    [_bottomView onUpdateCollection:isPraise];
}

#pragma mark 播放目前的音乐
- (void)play:(UIButton *)sender {
    playBtn.selected = !playBtn.selected;
    if (isPlay) {
        [audioPlayer play];
        [playBtn setBackgroundImage:[UIImage imageNamed:@"zanting_xbtj"] forState:UIControlStateSelected];
        [playBtn setBackgroundImage:[UIImage imageNamed:@"bofang_xbtj"]forState:UIControlStateNormal];
     
        
        if (!_showTimer) {
            //设置监控 每秒刷新一次时间
            _showTimer =[NSTimer scheduledTimerWithTimeInterval:0.1f
                                                         target:self
                                                       selector:@selector(showTime)
                                                       userInfo:nil
                                                        repeats:YES];
        }
    } else {
        [audioPlayer pause];
        [playBtn setBackgroundImage:[UIImage imageNamed:@"zanting_xbtj"] forState:UIControlStateSelected];
        [playBtn setBackgroundImage:[UIImage imageNamed:@"bofang_xbtj"]forState:UIControlStateNormal];
     
        
        if (_showTimer) {
            [_showTimer invalidate];
            _showTimer = nil;
        }
    }
}

#pragma mark 0.1秒一次更新 播放时间 播放进度条 歌词 歌曲 自动播放下一首
- (void)showTime {
    
    //动态更新进度条时间
    int currentTime = 0;
    int durationTime = 0;
    if (audioPlayer.currentItem.currentTime.timescale != 0) {
        currentTime = (int)(audioPlayer.currentItem.currentTime.value / audioPlayer.currentItem.currentTime.timescale);
    }
    if (audioPlayer.currentItem.duration.timescale != 0) {
        durationTime = (int) (audioPlayer.currentItem.duration.value / audioPlayer.currentItem.duration.timescale);
    }
    if ((int)currentTime % 60 < 10) {
        currentTimeLabel.text = [NSString stringWithFormat:@"%d:0%d",(int)currentTime / 60, (int)currentTime % 60];
    } else {
        currentTimeLabel.text = [NSString stringWithFormat:@"%d:%d",(int)currentTime / 60, (int)currentTime % 60];
    }
    //
    if ((int)durationTime % 60 < 10) {
        totalTimeLabel.text = [NSString stringWithFormat:@"%d:0%d",(int)durationTime / 60, (int)durationTime % 60];
    } else {
        totalTimeLabel.text = [NSString stringWithFormat:@"%d:%d",(int)durationTime / 60, (int)durationTime % 60];
    }
    progressSlider.value = 1.0 * currentTime / durationTime;
    if ([totalTimeLabel.text isEqualToString:@"0:00"]) {
        ++nextPlay;
        if (nextPlay == 8) {
            [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        }
        if (nextPlay == 60) {
            [audioPlayer replaceCurrentItemWithPlayerItem:nil];
            [self autoPlay];
            nextPlay = 1;
            [audioPlayer play];
            return;
        }
    } else {
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        nextPlay = 1;
    }
    //NSLog(@"当前时间:%@，总时间:%@,进度：%.2f",currentTimeLabel.text,totalTimeLabel.text,progressSlider.value);
    
    //收藏状态
    
    
    if (lrcTableView.isHidden == NO) {
        [self displaySondWord:currentTime];//调用歌词函数
    }
    
    //如果播放完，调用自动播放下一首
    if (progressSlider.value > 0.999) {
        [self autoPlay];
    }
}

#pragma mark 动态显示歌词
- (void)displaySondWord:(NSUInteger)time {
    //    NSLog(@"time = %u",time);
    for (int i = 0; i < [timeArray count]; i++) {
        
        NSArray *array = [timeArray[i] componentsSeparatedByString:@":"];//把时间转换成秒
        NSUInteger currentTime = [array[0] intValue] * 60 + [array[1] intValue];
        if (i == [timeArray count]-1) {
            //求最后一句歌词的时间点
            NSArray *array1 = [timeArray[timeArray.count-1] componentsSeparatedByString:@":"];
            NSUInteger currentTime1 = [array1[0] intValue] * 60 + [array1[1] intValue];
            if (time > currentTime1) {
                [self updateLrcTableView:i];
                break;
            }
        } else {
            //求出第一句的时间点，在第一句显示前的时间内一直加载第一句
            NSArray *array2 = [timeArray[0] componentsSeparatedByString:@":"];
            NSUInteger currentTime2 = [array2[0] intValue] * 60 + [array2[1] intValue];
            if (time < currentTime2) {
                [self updateLrcTableView:0];
                //                NSLog(@"马上到第一句");
                break;
            }
            //求出下一步的歌词时间点，然后计算区间
            NSArray *array3 = [timeArray[i+1] componentsSeparatedByString:@":"];
            NSUInteger currentTime3 = [array3[0] intValue] * 60 + [array3[1] intValue];
            if (time >= currentTime && time <= currentTime3) {
                [self updateLrcTableView:i];
                break;
            }
            
        }
    }
}

#pragma mark 动态更新歌词表歌词
- (void)updateLrcTableView:(NSUInteger)lineNumber {
    //重新载入 歌词列表lrcTabView
    lrcLineNumber = lineNumber;
    //    [lrcTableView reloadData];
    //    //使被选中的行移到中间
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:lineNumber inSection:0];
    [lrcTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
    //    [lrcTableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
    [lrcTableView reloadData];
    
    //表的显示区域最多显示的歌词行数
    int count = lrcTableView.height / TABLE_ROW_HEIGHT;
    count = count / 2;
    
    if (lineNumber > count) {
        //显示在这行时，开始往上移动一个单元格高度
        
        [lrcTableView setContentOffset:CGPointMake(0, TABLE_ROW_HEIGHT*(lineNumber-count)) animated:YES];
    } else {
        [lrcTableView setContentOffset:CGPointMake(0, 0) animated:YES];
    }
}

#pragma mark 自动进入下一首
- (void)autoPlay {
    if (playModelType == PLayerModelType_Shunxu) {
        //顺序
        if (musicArrayNumber == musicArray.count - 1) {
            musicArrayNumber = -1;
        }
        musicArrayNumber ++;
    }
    else if (playModelType == PLayerModelType_SuiJi) {
        musicArrayNumber = arc4random()%(musicArray.count);
    }
    else if (playModelType == PLayerModelType_DanQu) {
    
    }
    
    [self updatePlayerSetting];
}

#pragma mark 上一首
- (void)aboveMusic:(id)sender {
    if (playModelType == PLayerModelType_Shunxu) {
        //顺序
        if (musicArrayNumber == 0) {
            musicArrayNumber = musicArray.count;
        }
        musicArrayNumber --;
    }
    else if (playModelType == PLayerModelType_SuiJi) {
        musicArrayNumber = arc4random()%(musicArray.count);
    }
    else if (playModelType == PLayerModelType_DanQu) {
        if (musicArrayNumber == 0) {
            musicArrayNumber = musicArray.count;
        }
        musicArrayNumber --;

    }
    
    [self updatePlayerSetting];
}
#pragma mark 下一首
- (void)nextMusic:(id)sender {
    if (playModelType == PLayerModelType_Shunxu) {
        //顺序
        if (musicArrayNumber == musicArray.count - 1) {
            musicArrayNumber = -1;
        }
        musicArrayNumber ++;
    }
    else if (playModelType == PLayerModelType_SuiJi) {
        musicArrayNumber = arc4random()%(musicArray.count);
    }
    else if (playModelType == PLayerModelType_DanQu) {
        if (musicArrayNumber == musicArray.count - 1) {
            musicArrayNumber = -1;
        }
        musicArrayNumber ++;
    }
    
    [self updatePlayerSetting];
}

//更新播放器设置
- (void)updatePlayerSetting {
    
    [self setTitleView:[musicArray[musicArrayNumber] name]];
    
    //更新播放按钮状态
    [playBtn setBackgroundImage:[UIImage imageNamed:@"zanting_xbtj"] forState:UIControlStateSelected];
    isPlay = NO;
    
    //更新曲目
    [audioPlayer pause];
    currentMusic = musicArray[musicArrayNumber];
    songName.text = [musicArray[musicArrayNumber] name];
    singer.text = [musicArray[musicArrayNumber] Singer];
    
    NSURL *urlPath;
    if (currentMusic.isCacheData) {
        NSString *filePath = [MusicCachesDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp3",currentMusic.name]];
        urlPath = [NSURL fileURLWithPath:filePath];
    } else {
        urlPath = [NSURL URLWithString:currentMusic.urlPath];
    }
    
    AVPlayerItem *item =[AVPlayerItem playerItemWithURL:urlPath];
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [audioPlayer replaceCurrentItemWithPlayerItem:nil];
        [audioPlayer replaceCurrentItemWithPlayerItem:item];
        if (playBtn.selected) {
            [audioPlayer play];
        } else {
            [audioPlayer pause];
        }

    });
    
    //重新载入歌词词典
    [self initLRC];
    
}

- (void)progressChange:(id)sender {
    
    CGFloat duration = audioPlayer.currentItem.duration.value / audioPlayer.currentItem.duration.timescale;
    NSInteger dragedSeconds = floorf(duration*progressSlider.value);
    
    //转换成CMTime才能给player来控制播放进度
    CMTime dragedCMTime = CMTimeMake(dragedSeconds, 1);
    
    [audioPlayer pause];
    [_showTimer invalidate];
    _showTimer = nil;
    [audioPlayer seekToTime:dragedCMTime completionHandler:^(BOOL finish){
        if (finish) {
            if (!_showTimer) {
                //设置监控 每秒刷新一次时间
                _showTimer =[NSTimer scheduledTimerWithTimeInterval:0.1f
                                                             target:self
                                                           selector:@selector(showTime)
                                                           userInfo:nil
                                                            repeats:YES];
            }
            [audioPlayer play];
        }
        
    }];
}

- (IBAction)circle:(id)sender {
    if (isCircle) {
        circleBtn.alpha = 0.5;
        isCircle = NO;
    } else {
        circleBtn.alpha = 1.0;
        isCircle = YES;
    }
}

#pragma mark 表视图
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [timeArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"LRCCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;//该表格选中后没有颜色
    cell.backgroundColor = [UIColor clearColor];
    if (indexPath.row == lrcLineNumber) {
        if (timeArray.count > indexPath.row) {
            cell.textLabel.text = LRCDictionary[timeArray[indexPath.row]];
        }
        cell.textLabel.textColor = [[UIColor whiteColor]colorWithAlphaComponent:1.];//[UIColor colorWithRed:0 green:0 blue:0 alpha:1.0];
        cell.textLabel.font = [UIFont systemFontOfSize:17];
    } else {
        if (timeArray.count > indexPath.row) {
            cell.textLabel.text = LRCDictionary[timeArray[indexPath.row]];
        }
        cell.textLabel.textColor = [[UIColor whiteColor] colorWithAlphaComponent:.5];//[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
        cell.textLabel.font = [UIFont systemFontOfSize:15];
    }

    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.textLabel.textAlignment = NSTextAlignmentCenter;

    return cell;
}
//行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return TABLE_ROW_HEIGHT;
}
//选中后的响应函数
- (void)playTable:(NSUInteger)tableNumber {
    musicArrayNumber = tableNumber;
    [self updatePlayerSetting];
}

#pragma mark - 收藏、播放类型、下载、分享
//收藏
- (void)onSelectCollectionMusicWithValue:(id)value
{
    UserModel *model = [UserManager standerDefult].userModel;
    if (!model.UserID) {
        MBLoginController *registerLastVC = [[MBLoginController alloc] init];
        registerLastVC.formBaseViewCtrl = NSStringFromClass([self class]);
        [self.navigationController pushViewController:registerLastVC animated:YES];
        return;
    }
    
    if (!model) return;
    
    //区分收藏和未收藏
    NSString *idStr = currentMusic.ID;
    if ([collectionMusicArr containsObject:idStr] || [collectionMusicArr containsObject:currentMusic.ID]) {
        //取消收藏
        [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        [[HTTPManager standerDefault]AFGetRequest:[NSString stringWithFormat:SPACE_COLLECTION_REMOVE_URL_PATH,model.UserID,currentMusic.ID,@1] view:nil success:^(id json) {
            [MBProgressHUD hideHUDForView:self.view animated:YES];
            
            if ([json[@"ret_code"] integerValue]==0) {
                //取消点赞成功
                [_bottomView onUpdateCollection:NO];
                
                //数据更新
                if ([collectionMusicArr containsObject:idStr]) {
                    [collectionMusicArr removeObject:idStr];
                }
                else if ([collectionMusicArr containsObject:currentMusic.ID]) {
                    [collectionMusicArr removeObject:currentMusic.ID];
                }
                [[UserManager standerDefult].collectionMusicArr removeAllObjects];
                [[UserManager standerDefult].collectionMusicArr addObjectsFromArray:collectionMusicArr];
            } else {
                [ErrorMessage showErrorMessage:json[@"message"] inView:self.view];
            }
        } failure:^(NSError *error) {
            [MBProgressHUD hideHUDForView:self.view animated:YES];
        }];
    } else  {
        //收藏
        [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        [[HTTPManager standerDefault]AFGetRequest:[NSString stringWithFormat:SPACE_COLLECTION_COLLECION_URL_PATH,model.UserID,currentMusic.ID,@1] view:nil success:^(id json) {
            [MBProgressHUD hideHUDForView:self.view animated:YES];
            
            if ([json[@"ret_code"] integerValue]==0) {
                //点赞成功
                [_bottomView onUpdateCollection:YES];
                
                //数据更新
                if (![collectionMusicArr containsObject:idStr]) {
                    [collectionMusicArr addObject:idStr];
                }
                [[UserManager standerDefult].collectionMusicArr removeAllObjects];
                [[UserManager standerDefult].collectionMusicArr addObjectsFromArray:collectionMusicArr];
                
                AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
                if ([UserManager standerDefult].isLoadMusic == YES && app.networkStatus == ReachableViaWiFi) {
                    [self onSelectDownMusicWithValue:[NSNumber numberWithBool:_bottomView.isDownLoad]];
                }
            } else {
                [ErrorMessage showErrorMessage:json[@"message"] inView:self.view];
            }
        } failure:^(NSError *error) {
            [MBProgressHUD hideHUDForView:self.view animated:YES];
        }];
    }

}
//播放模式
- (void)onSelectPLayMusicTypeWithValue:(PLayerModelType)value
{
    [_bottomView onUpdatePlayMusicType:value];
    playModelType = value;
}
//下载歌曲
- (void)onSelectDownMusicWithValue:(id)value
{  UserModel *model = [UserManager standerDefult].userModel;
    if (!model.UserID) {
        MBLoginController *registerLastVC = [[MBLoginController alloc] init];
        registerLastVC.formBaseViewCtrl = NSStringFromClass([self class]);
        [self.navigationController pushViewController:registerLastVC animated:YES];
        return;
    }
    
    if ([value boolValue] == YES) {
        //已下载
        return;
    }
    
    
    NSDictionary *dic = @{@"ID":currentMusic.ID,@"AudioPath":currentMusic.AudioPath,@"AudioStatus":currentMusic.AudioStatus,@"AudioName":[NSString stringWithFormat:@"%@.%@",currentMusic.name,currentMusic.type],@"ValueID":currentMusic.musicType};
    [[UserManager standerDefult]downLoadMusic:dic withRequestArr:fileIDArr];
    [ErrorMessage showErrorMessage:@"开始下载" inView:self.view];
    
    //下载次数接口
    [MBProgressHUD showHUDAddedTo:blurryView animated:YES];
    [[HTTPManager standerDefault]AFGetRequest:[NSString stringWithFormat:FAMILYSHOW_DOWN_LOADNUM_URL_PATH,model.UserID,currentMusic.ID,@1] view:nil success:^(id json) {
        [MBProgressHUD hideHUDForView:blurryView animated:YES];
        
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUDForView:blurryView animated:YES];
    }];
    
    [_bottomView onUpdateDown:NO withModel:currentMusic];
    [_bottomView onEnabledUpdateDown];


}
//分享
- (void)onSelectShareMusicWithValue:(id)value
{
    UserModel *model = [UserManager standerDefult].userModel;
    if (!model.UserID) {
        MBLoginController *registerLastVC = [[MBLoginController alloc] init];
        registerLastVC.formBaseViewCtrl = NSStringFromClass([self class]);
        [self.navigationController pushViewController:registerLastVC animated:YES];
        return;
    }
    
    [shareView setShareVC:self content:[NSString stringWithFormat:@"分享:%@",currentMusic.name] image:[UIImage imageNamed:@"logo_dl_29"] url:[NSString stringWithFormat:SHARE_MUSIC_URL_PATH,currentMusic.ID]];
    [shareView addAudioId:[NSString stringWithFormat:@"%@",currentMusic.ID] withType:@1];
    [shareView show];

}
#pragma mark -远程控制
- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent
{
    if (receivedEvent.type == UIEventTypeRemoteControl) {
        switch (receivedEvent.subtype) {
            case UIEventSubtypeRemoteControlTogglePlayPause:
                [audioPlayer pause];
                break;
            case UIEventSubtypeRemoteControlNextTrack:
                [self nextMusic:nextBt];
                break;
            case UIEventSubtypeRemoteControlPreviousTrack:
                [self aboveMusic:lastBtn];
                break;
            case UIEventSubtypeRemoteControlPause:
                
                [audioPlayer pause];
                break;
            case UIEventSubtypeRemoteControlPlay:
                [audioPlayer play];
                break;
            default:
                break;
        }
    }
}

@end
